home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / source / gurumode / guru-c.asm < prev    next >
Assembly Source File  |  1993-01-16  |  6KB  |  171 lines

  1. ;----------------------------------------------------------------------------
  2. ;GuruMode    -    12 new 256 color modes for the IBM VGA and
  3. ;            compatibles.  (all modes are "tweaked" modes, e.g.
  4. ;            four bitplanes are used, with a complete pixel in
  5. ;            each plane.)
  6. ;Calling protocol    int gurumode(unsigned int mode);
  7. ;Valid values mode for are:
  8. ;        0    320x175            6    360x175
  9. ;        1    320x200            7    360x200
  10. ;        2    320x240            8    360x240
  11. ;        3    320x350            9    360x350
  12. ;        4    320x400            a    360x400
  13. ;        5    320x480            b    360x480
  14. ;
  15. ;Returns    0    if call was successful
  16. ;        -1    if VGA wasn't detected
  17. ;        -2    if selected mode was out of range
  18. ;
  19. ;Terms of use    -    Use and distribute freely as long as source remains
  20. ;            100% unchanged.  Donations of 10$, or any amount
  21. ;            are received with gratitude (I'm a student with
  22. ;            a rather tigth budget).
  23. ;                    (C) 8-02-1992 Per Ole Klemetsrud
  24. ;                    Hertug Skulesgt. 15c
  25. ;                    0652 Oslo, Norway
  26. ;
  27. ;Clarke's Third Law:    "Any sufficiently advanced technology is
  28. ;             indistinguishable from magic."
  29. ;----------------------------------------------------------------------------
  30.         .model  small
  31.         .code
  32.         public  _gurumode
  33. _gurumode proc  NEAR mode:WORD
  34.         push    bp              ;Save stack pointer
  35.         mov     bp,sp           ;Get new stack pointer
  36.         push    si
  37.         push    di
  38.  
  39.     mov    ax,01a00h    ;VGA BIOS returns 01Ah in AL if call was valid
  40.     int    10h
  41.     cmp    al,01ah
  42.     je    VGApresent
  43.     mov    ax,-1
  44.     jmp    exit
  45. VGApresent:
  46.     mov    ax,-2        ;Error code
  47.     mov    bx,[mode]    ;Get selected mode
  48.     cmp    bx,0bh        ;Check if mode is valid
  49.     jg    exit
  50.  
  51.     mov    ax,0013h
  52.     int    10h        ;Start with BIOS mode 13h
  53.  
  54.     mov    dx,03c4h    ;Sequencer Register
  55.     mov    cl,[clocktab+bx]
  56.     cmp    cl,00h        ;Check if reset is necessary
  57.     je    Skip_Reset
  58.  
  59.         mov    ax,0100h    ;Index 0, (Reset Register)
  60.         out    dx,ax        ;Set the system in reset conditon
  61.  
  62.         mov    dx,3c2h        ;Miscellaneous output register
  63.         mov    al,cl        ;Set new sync polarity and clock frequency
  64.         out    dx,al
  65.  
  66.         mov    dx,3c4h        ;Sequencer register
  67.         mov    ax,0300h    ;Index 0, (Reset Register)
  68.         out    dx,ax        ;Release reset
  69. Skip_Reset:
  70.         mov    ax,0604h    ;Index 4, Disable Chain 4 (Set bit 3 to 0)
  71.         out    dx,ax        ;Part of the "Tweak Settings"
  72.  
  73.     mov    ax,0a000h    ;This is a good time to clear RAM to
  74.     mov    es,ax        ;avoid a flick of trash during mode change
  75.     xor    di,di
  76.     xor    ah,ah        ;ES:DI=Video Ram, AX=0000
  77.     mov    cx,(0ffffh/2)    ;Entire Video Segment in words
  78. rep    stosw
  79.  
  80.         mov    dx,03d4h    ;Start filling the CRT controller registers
  81.         mov    si,offset [Regtab]
  82.     mov    cx,3        ;Start with the "tweak mode" settings
  83.     cmp    bl,5        ;and continue with horizontal settings
  84.     jbe    CRT1        ;if necessary
  85.     mov    cx,10
  86.  
  87. CRT1:      lodsw
  88.     out    dx,ax
  89.     loop    CRT1        ;Now thru with "Tweak" settings
  90.  
  91.     shl    bx,1        ;Make BX a word index, instead of a byte index
  92.     mov    si,[vertab+bx]    ;Get address of table to use
  93.     cmp    si,0
  94.     je    noerr        ;Do more changes necessary.
  95.     cmp    si,1        
  96.     je    Set400
  97.  
  98.     mov    cx,8        ;Fill CRT controller registers with
  99. CRT2:    lodsw            ;info about horizontal resolution.
  100.     out    dx,ax
  101.     loop    CRT2
  102.  
  103. noerr:    xor    ax,ax
  104. exit:    pop     di
  105.     pop     si
  106.     pop     bp        ;Restore registers
  107.     ret
  108.  
  109. Set400:    mov    ax,04009h    ;Mode only requiers normal vertical resolution
  110.     out    dx,ax
  111.     jmp    noerr
  112.  
  113. _gurumode endp
  114.  
  115.         .data
  116. Regtab    label    word
  117.     dw    00e11h        ;Index 11, Turn off write protect
  118.     dw    00014h        ;Index 14, Turn off dword mode
  119.     dw    0e317h        ;Index 17, Turn on byte mode
  120. ;----------------------------------------------------------------------------
  121. ;Data to the set the CRT controller to 360 horizontal pixels.
  122. ;Horizontal retrace and blanking periods are based on mode 10h and 12h.
  123. ;----------------------------------------------------------------------------
  124.     db    00h,06bh    ;Horizontal Total        107
  125.     db    01h,059h    ;Horizontal Display End         89
  126.     db    02h,05ah    ;Start Horizontal Blanking     90
  127.     db    03h,08eh    ;End Horizontal Blanking     
  128.     db    04h,05eh    ;Start Horizontal Retrace     94
  129.     db    05h,08ah    ;End Horizontal Retrace      
  130.     db    13h,02dh    ;Offset register         90
  131.  
  132. ;----------------------------------------------------------------------------
  133. ;Data to the set the CRT controller to 480 scanlines, originaly used 
  134. ;by BIOS mode 12h.  Refer to Programmers guide to the EGA/VGA, by 
  135. ;Richard F. Ferraro for details about display timing.
  136. ;----------------------------------------------------------------------------
  137. vert480    label    word
  138.     db    009h,01000000b    ;Maximum Scan Line          0
  139.     db    007h,00111110b    ;Overflow register
  140.     db    006h,00bh    ;Vertical Total            523
  141.     db    010h,0eah    ;Vertical Retrace Start     490
  142.     db    011h,08ch    ;Vertical Retrace End
  143.     db    015h,0e7h    ;Start Vertical Blanking    487
  144.     db    016h,004h    ;End Vertical Blanking
  145.     db    012h,0dfh    ;Vertical Display End        479
  146.     db    012h,0dfh    ;Safe dummy for neat program flow
  147. ;----------------------------------------------------------------------------
  148. ;Data to the CRT controller to set the display to 350 scanlines,
  149. ;originaly used by BIOS mode 10h.  Refer to Programmers guide to the EGA/VGA,
  150. ;by Richard F. Ferraro for details about display timing.
  151. ;----------------------------------------------------------------------------
  152. vert350    label    word
  153.     db    009h,01000000b    ;Maximum Scan Line          0
  154.     db    007h,00011111b    ;Overflow register
  155.     db    006h,0bfh    ;Vertical Total            447
  156.     db    010h,083h    ;Vertical Retrace Start     387
  157.     db    011h,085h    ;Vertical Retrace End
  158.     db    015h,063h    ;Start Vertical Blanking    355
  159.     db    016h,0bah    ;End Vertical Blanking
  160.     db    012h,05dh    ;Vertical Display End        349
  161.     db    012h,05dh    ;Safe dummy for neat program flow
  162. ;----------------------------------------------------------------------------
  163. ;Sync polarities and horizontal clock frequencies for the different modes
  164. ;----------------------------------------------------------------------------
  165. clocktab    label    byte
  166.     db    0a3h, 000h, 0e3h, 0a3h, 000h, 0e3h
  167.     db    0a7h, 067h, 0e7h, 0a7h, 067h, 0e7h
  168.  
  169. vertab    dw    vert350+2,0000h, vert480+2, vert350, 0001h, vert480
  170.     dw    vert350+2,0000h, vert480+2, vert350, 0001h, vert480
  171.         end